package thread.sync.lock;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class LockCounter implements Runnable {
	private int v = 0;
	int count = 0;
	private Lock lock = new ReentrantLock();

	@Override
	public void run() {
		lock.lock();

		increment();
		decrement();

		if (v != 0) {
			count++;
		}

		lock.unlock();
	}

	public void increment() {
    	for (int i=0; i < 1000000; i++){
    		v++;
    	}
    }

    public void decrement() {
    	for (int i=0; i < 1000000; i++){
    		v--;
    	}
    }
}
